﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;

/// <summary>
/// Summary description for Helper
/// </summary>
public static class Helper
{
    /// <summary>
    /// For customer site
    /// </summary>
    /// <param name="dtab"></param>
    /// <returns></returns>
    public static string getCurrentUserName(System.Data.DataTable dtab)
    {
        return dtab.Rows[0]["UserName"].ToString();
    }

    public static string getCurrentPageName(Uri uri, bool onlyPageName = true)
    {
        string url = uri.ToString();
        string full = url.Substring(url.LastIndexOf('/') + 1);
        int paramIndex = full.IndexOf("?");
        
        if (onlyPageName && paramIndex != -1)
        {
            return full.Remove(paramIndex);
        }

        return full;
    }

    public static string getCurrentAdminRole(System.Web.SessionState.HttpSessionState session)
    {
        return (string)session["Admin_Role"];
    }

    public static string getCurrentAdminUserName(System.Web.SessionState.HttpSessionState session)
    {
        return (string)session["Admin_UN"];
    }

    public static void setCurrentAminUserName(System.Web.SessionState.HttpSessionState session, string adminUserName)
    {
        session["Admin_UN"] = adminUserName;
    }

    public static void setCurrentAdminRole(System.Web.SessionState.HttpSessionState session, string adminRole)
    {
        session["Admin_Role"] = adminRole;
    }

    public static int getCurrentAdminQuyen(object masterPage)
    {
        return ((QL_MasterPage)masterPage).Quyen;
    }

    public static void setWantedPage(System.Web.SessionState.HttpSessionState session, string pageName)
    {
        session["Admin_WantedPage"] = pageName;
    }

    public static string getWantedPage(System.Web.SessionState.HttpSessionState session)
    {
        return (string)session["Admin_WantedPage"];
    }

    public static string CreateMessageBox(string message)
    {
        return "<script>alert('" + message + "');</script>";
    }

    public static int calPageIndexForDetailView(GridView gv)
    {
        return gv.PageIndex * gv.PageSize + gv.SelectedIndex;
    }

    public static void changeGVPageIndex(GridView gv, int newPageIndex)
    {
        gv.PageIndex = newPageIndex;
        gv.DataBind();
    }
}